<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>bidiformatter_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_i18n_bidiformatter_test.js.html">bidiformatter_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2009 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.i18n.BidiFormatterTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.i18n.BidiFormatterTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.i18n.BidiFormatter&#39;);
<a name="line19"></a>goog.require(&#39;goog.i18n.bidi.Dir&#39;);
<a name="line20"></a>goog.require(&#39;goog.i18n.bidi.Format&#39;);
<a name="line21"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line22"></a>
<a name="line23"></a>var LRM = goog.i18n.bidi.Format.LRM;
<a name="line24"></a>var RLM = goog.i18n.bidi.Format.RLM;
<a name="line25"></a>var LRE = goog.i18n.bidi.Format.LRE;
<a name="line26"></a>var RLE = goog.i18n.bidi.Format.RLE;
<a name="line27"></a>var PDF = goog.i18n.bidi.Format.PDF;
<a name="line28"></a>var LTR = goog.i18n.bidi.Dir.LTR;
<a name="line29"></a>var RTL = goog.i18n.bidi.Dir.RTL;
<a name="line30"></a>var NEUTRAL = goog.i18n.bidi.Dir.NEUTRAL;
<a name="line31"></a>var he = &#39;\u05e0\u05e1&#39;;
<a name="line32"></a>var en = &#39;abba&#39;;
<a name="line33"></a>var html = &#39;&amp;lt;&#39;;
<a name="line34"></a>var longEn = &#39;abba sabba gabba &#39;;
<a name="line35"></a>var longHe = &#39;\u05e0 \u05e1 \u05e0 &#39;;
<a name="line36"></a>var ltrFmt = new goog.i18n.BidiFormatter(LTR, false);  // LTR context
<a name="line37"></a>var rtlFmt = new goog.i18n.BidiFormatter(RTL, false);  // RTL context
<a name="line38"></a>var unkFmt = new goog.i18n.BidiFormatter(null, false);  // unknown context
<a name="line39"></a>
<a name="line40"></a>function testGetContextDir() {
<a name="line41"></a>  assertEquals(null, unkFmt.getContextDir());
<a name="line42"></a>  assertEquals(null, new goog.i18n.BidiFormatter(NEUTRAL).getContextDir());
<a name="line43"></a>  assertEquals(LTR, ltrFmt.getContextDir());
<a name="line44"></a>  assertEquals(RTL, rtlFmt.getContextDir());
<a name="line45"></a>}
<a name="line46"></a>
<a name="line47"></a>function testEstimateDirection() {
<a name="line48"></a>  assertEquals(NEUTRAL, ltrFmt.estimateDirection(&#39;&#39;));
<a name="line49"></a>  assertEquals(NEUTRAL, rtlFmt.estimateDirection(&#39;&#39;));
<a name="line50"></a>  assertEquals(NEUTRAL, unkFmt.estimateDirection(&#39;&#39;));
<a name="line51"></a>  assertEquals(LTR, ltrFmt.estimateDirection(en));
<a name="line52"></a>  assertEquals(LTR, rtlFmt.estimateDirection(en));
<a name="line53"></a>  assertEquals(LTR, unkFmt.estimateDirection(en));
<a name="line54"></a>  assertEquals(RTL, ltrFmt.estimateDirection(he));
<a name="line55"></a>  assertEquals(RTL, rtlFmt.estimateDirection(he));
<a name="line56"></a>  assertEquals(RTL, unkFmt.estimateDirection(he));
<a name="line57"></a>
<a name="line58"></a>  // Text contains HTML or HTML-escaping.
<a name="line59"></a>  assertEquals(LTR, ltrFmt.estimateDirection(
<a name="line60"></a>      &#39;&lt;some sort of tag/&gt;&#39; + he + &#39; &amp;amp;&#39;, false));
<a name="line61"></a>  assertEquals(RTL, ltrFmt.estimateDirection(
<a name="line62"></a>      &#39;&lt;some sort of tag/&gt;&#39; + he + &#39; &amp;amp;&#39;, true));
<a name="line63"></a>}
<a name="line64"></a>
<a name="line65"></a>function testDirAttrValue() {
<a name="line66"></a>  assertEquals(&#39;overall dir is RTL, context dir is LTR&#39;,
<a name="line67"></a>      &#39;rtl&#39;, ltrFmt.dirAttrValue(he, true));
<a name="line68"></a>  assertEquals(&#39;overall dir and context dir are RTL&#39;,
<a name="line69"></a>      &#39;rtl&#39;, rtlFmt.dirAttrValue(he, true));
<a name="line70"></a>  assertEquals(&#39;overall dir is LTR, context dir is RTL&#39;,
<a name="line71"></a>      &#39;ltr&#39;, rtlFmt.dirAttrValue(en, true));
<a name="line72"></a>  assertEquals(&#39;overall dir and context dir are LTR&#39;,
<a name="line73"></a>      &#39;ltr&#39;, ltrFmt.dirAttrValue(en, true));
<a name="line74"></a>
<a name="line75"></a>  // Input&#39;s directionality is neutral.
<a name="line76"></a>  assertEquals(&#39;ltr&#39;, ltrFmt.dirAttrValue(&#39;&#39;, true));
<a name="line77"></a>  assertEquals(&#39;rtl&#39;, rtlFmt.dirAttrValue(&#39;&#39;, true));
<a name="line78"></a>  assertEquals(&#39;ltr&#39;, unkFmt.dirAttrValue(&#39;&#39;, true));
<a name="line79"></a>
<a name="line80"></a>  // Text contains HTML or HTML-escaping:
<a name="line81"></a>  assertEquals(&#39;rtl&#39;,
<a name="line82"></a>      ltrFmt.dirAttrValue(he + &#39;&lt;some sort of an HTML tag&gt;&#39;, true));
<a name="line83"></a>  assertEquals(&#39;ltr&#39;,
<a name="line84"></a>      ltrFmt.dirAttrValue(he + &#39;&lt;some sort of an HTML tag&gt;&#39;, false));
<a name="line85"></a>}
<a name="line86"></a>
<a name="line87"></a>function testKnownDirAttrValue() {
<a name="line88"></a>  assertEquals(&#39;rtl&#39;, ltrFmt.knownDirAttrValue(RTL));
<a name="line89"></a>  assertEquals(&#39;rtl&#39;, rtlFmt.knownDirAttrValue(RTL));
<a name="line90"></a>  assertEquals(&#39;rtl&#39;, unkFmt.knownDirAttrValue(RTL));
<a name="line91"></a>  assertEquals(&#39;ltr&#39;, rtlFmt.knownDirAttrValue(LTR));
<a name="line92"></a>  assertEquals(&#39;ltr&#39;, ltrFmt.knownDirAttrValue(LTR));
<a name="line93"></a>  assertEquals(&#39;ltr&#39;, unkFmt.knownDirAttrValue(LTR));
<a name="line94"></a>
<a name="line95"></a>  // Input directionality is neutral.
<a name="line96"></a>  assertEquals(&#39;ltr&#39;, ltrFmt.knownDirAttrValue(NEUTRAL));
<a name="line97"></a>  assertEquals(&#39;rtl&#39;, rtlFmt.knownDirAttrValue(NEUTRAL));
<a name="line98"></a>  assertEquals(&#39;ltr&#39;, unkFmt.knownDirAttrValue(NEUTRAL));
<a name="line99"></a>}
<a name="line100"></a>
<a name="line101"></a>function testDirAttr() {
<a name="line102"></a>  assertEquals(&#39;overall dir (RTL) doesnt match context dir (LTR)&#39;,
<a name="line103"></a>      &#39;dir=&quot;rtl&quot;&#39;, ltrFmt.dirAttr(he, true));
<a name="line104"></a>  assertEquals(&#39;overall dir (RTL) doesnt match context dir (unknown)&#39;,
<a name="line105"></a>      &#39;dir=&quot;rtl&quot;&#39;, unkFmt.dirAttr(he, true));
<a name="line106"></a>  assertEquals(&#39;overall dir matches context dir (RTL)&#39;,
<a name="line107"></a>      &#39;&#39;, rtlFmt.dirAttr(he, true));
<a name="line108"></a>
<a name="line109"></a>  assertEquals(&#39;overall dir (LTR) doesnt match context dir (RTL)&#39;,
<a name="line110"></a>      &#39;dir=&quot;ltr&quot;&#39;, rtlFmt.dirAttr(en, true));
<a name="line111"></a>  assertEquals(&#39;overall dir (LTR) doesnt match context dir (unknown)&#39;,
<a name="line112"></a>      &#39;dir=&quot;ltr&quot;&#39;, unkFmt.dirAttr(en, true));
<a name="line113"></a>  assertEquals(&#39;overall dir matches context dir (LTR)&#39;,
<a name="line114"></a>      &#39;&#39;, ltrFmt.dirAttr(en, true));
<a name="line115"></a>
<a name="line116"></a>  assertEquals(&#39;neutral in RTL context&#39;,
<a name="line117"></a>      &#39;&#39;, rtlFmt.dirAttr(&#39;.&#39;, true));
<a name="line118"></a>  assertEquals(&#39;neutral in LTR context&#39;,
<a name="line119"></a>      &#39;&#39;, ltrFmt.dirAttr(&#39;.&#39;, true));
<a name="line120"></a>  assertEquals(&#39;neutral in unknown context&#39;,
<a name="line121"></a>      &#39;&#39;, unkFmt.dirAttr(&#39;.&#39;, true));
<a name="line122"></a>
<a name="line123"></a>  // Text contains HTML or HTML-escaping:
<a name="line124"></a>  assertEquals(&#39;dir=&quot;rtl&quot;&#39;,
<a name="line125"></a>      ltrFmt.dirAttr(he + &#39;&lt;some sort of an HTML tag&gt;&#39;, true));
<a name="line126"></a>  assertEquals(&#39;&#39;,
<a name="line127"></a>      ltrFmt.dirAttr(he + &#39;&lt;some sort of an HTML tag&gt;&#39;, false));
<a name="line128"></a>}
<a name="line129"></a>
<a name="line130"></a>function testKnownDirAttr() {
<a name="line131"></a>  assertEquals(&#39;overall dir (RTL) doesnt match context dir (LTR)&#39;,
<a name="line132"></a>      &#39;dir=&quot;rtl&quot;&#39;, ltrFmt.knownDirAttr(RTL));
<a name="line133"></a>  assertEquals(&#39;overall dir matches context dir (RTL)&#39;,
<a name="line134"></a>      &#39;&#39;, rtlFmt.knownDirAttr(RTL));
<a name="line135"></a>  assertEquals(&#39;overall dir (LTR) doesnt match context dir (RTL)&#39;,
<a name="line136"></a>      &#39;dir=&quot;ltr&quot;&#39;, rtlFmt.knownDirAttr(LTR));
<a name="line137"></a>  assertEquals(&#39;overall dir matches context dir (LTR)&#39;,
<a name="line138"></a>      &#39;&#39;, ltrFmt.knownDirAttr(LTR));
<a name="line139"></a>}
<a name="line140"></a>
<a name="line141"></a>function testSpanWrap() {
<a name="line142"></a>  // alwaysSpan is false and opt_isHtml is true, unless specified otherwise.
<a name="line143"></a>  assertEquals(&#39;overall dir matches context dir (LTR), no dirReset&#39;,
<a name="line144"></a>      en, ltrFmt.spanWrap(en, true, false));
<a name="line145"></a>  assertEquals(&#39;overall dir matches context dir (LTR), dirReset&#39;,
<a name="line146"></a>      en, ltrFmt.spanWrap(en, true, true));
<a name="line147"></a>  assertEquals(&#39;overall dir matches context dir (RTL), no dirReset&#39;,
<a name="line148"></a>      he, rtlFmt.spanWrap(he, true, false));
<a name="line149"></a>  assertEquals(&#39;overall dir matches context dir (RTL), dirReset&#39;,
<a name="line150"></a>      he, rtlFmt.spanWrap(he, true, true));
<a name="line151"></a>
<a name="line152"></a>  assertEquals(&#39;overall dir (RTL) doesnt match context dir (LTR), &#39; +
<a name="line153"></a>      &#39;no dirReset&#39;,
<a name="line154"></a>      &#39;&lt;span dir=&quot;rtl&quot;&gt;&#39; + he + &#39;&lt;\/span&gt;&#39;, ltrFmt.spanWrap(he, true, false));
<a name="line155"></a>  assertEquals(&#39;overall dir (RTL) doesnt match context dir (LTR), dirReset&#39;,
<a name="line156"></a>      &#39;&lt;span dir=&quot;rtl&quot;&gt;&#39; + he + &#39;&lt;\/span&gt;&#39; + LRM,
<a name="line157"></a>      ltrFmt.spanWrap(he, true, true));
<a name="line158"></a>  assertEquals(&#39;overall dir (LTR) doesnt match context dir (RTL), &#39; +
<a name="line159"></a>      &#39;no dirReset&#39;,
<a name="line160"></a>      &#39;&lt;span dir=&quot;ltr&quot;&gt;&#39; + en + &#39;&lt;\/span&gt;&#39;, rtlFmt.spanWrap(en, true, false));
<a name="line161"></a>  assertEquals(&#39;overall dir (LTR) doesnt match context dir (RTL), dirReset&#39;,
<a name="line162"></a>      &#39;&lt;span dir=&quot;ltr&quot;&gt;&#39; + en + &#39;&lt;\/span&gt;&#39; + RLM,
<a name="line163"></a>      rtlFmt.spanWrap(en, true, true));
<a name="line164"></a>  assertEquals(&#39;overall dir (LTR) doesnt match context dir (unknown), &#39; +
<a name="line165"></a>      &#39;no dirReset&#39;,
<a name="line166"></a>      &#39;&lt;span dir=&quot;ltr&quot;&gt;&#39; + en + &#39;&lt;\/span&gt;&#39;, unkFmt.spanWrap(en, true, false));
<a name="line167"></a>  assertEquals(&#39;overall dir (RTL) doesnt match context dir (unknown), &#39; +
<a name="line168"></a>      &#39;dirReset&#39;,
<a name="line169"></a>      &#39;&lt;span dir=&quot;rtl&quot;&gt;&#39; + he + &#39;&lt;\/span&gt;&#39;, unkFmt.spanWrap(he, true, true));
<a name="line170"></a>  assertEquals(&#39;overall dir (neutral) doesnt match context dir (LTR), &#39; +
<a name="line171"></a>      &#39;dirReset&#39;,
<a name="line172"></a>      &#39;&#39;,
<a name="line173"></a>      ltrFmt.spanWrap(&#39;&#39;, true, true));
<a name="line174"></a>
<a name="line175"></a>  assertEquals(&#39;exit dir (but not overall dir) is opposite to context dir, &#39; +
<a name="line176"></a>      &#39;dirReset&#39;,
<a name="line177"></a>      longEn + he + html + LRM,
<a name="line178"></a>      ltrFmt.spanWrap(longEn + he + html, true, true));
<a name="line179"></a>  assertEquals(&#39;overall dir (but not exit dir) is opposite to context dir, &#39; +
<a name="line180"></a>      &#39;dirReset&#39;,
<a name="line181"></a>      &#39;&lt;span dir=&quot;ltr&quot;&gt;&#39; + longEn + he + &#39;&lt;\/span&gt;&#39; + RLM,
<a name="line182"></a>      rtlFmt.spanWrap(longEn + he, true, true));
<a name="line183"></a>
<a name="line184"></a>  assertEquals(&#39;input is plain text (not escaped)&#39;,
<a name="line185"></a>      &#39;&amp;lt;br&amp;gt;&#39; + en,
<a name="line186"></a>      ltrFmt.spanWrap(&#39;&lt;br&gt;&#39; + en, false, false));
<a name="line187"></a>
<a name="line188"></a>  var ltrAlwaysSpanFmt = new goog.i18n.BidiFormatter(LTR, true);
<a name="line189"></a>  var rtlAlwaysSpanFmt = new goog.i18n.BidiFormatter(RTL, true);
<a name="line190"></a>  var unkAlwaysSpanFmt = new goog.i18n.BidiFormatter(null, true);
<a name="line191"></a>
<a name="line192"></a>  assertEquals(&#39;alwaysSpan, overall dir matches context dir (LTR), &#39; +
<a name="line193"></a>      &#39;no dirReset&#39;,
<a name="line194"></a>      &#39;&lt;span&gt;&#39; + en + &#39;&lt;\/span&gt;&#39;, ltrAlwaysSpanFmt.spanWrap(en, true, false));
<a name="line195"></a>  assertEquals(&#39;alwaysSpan, overall dir matches context dir (LTR), dirReset&#39;,
<a name="line196"></a>      &#39;&lt;span&gt;&#39; + en + &#39;&lt;\/span&gt;&#39;, ltrAlwaysSpanFmt.spanWrap(en, true, true));
<a name="line197"></a>  assertEquals(&#39;alwaysSpan, overall dir matches context dir (RTL), &#39; +
<a name="line198"></a>      &#39;no dirReset&#39;,
<a name="line199"></a>      &#39;&lt;span&gt;&#39; + he + &#39;&lt;\/span&gt;&#39;, rtlAlwaysSpanFmt.spanWrap(he, true, false));
<a name="line200"></a>  assertEquals(&#39;alwaysSpan, overall dir matches context dir (RTL), dirReset&#39;,
<a name="line201"></a>      &#39;&lt;span&gt;&#39; + he + &#39;&lt;\/span&gt;&#39;, rtlAlwaysSpanFmt.spanWrap(he, true, true));
<a name="line202"></a>
<a name="line203"></a>  assertEquals(&#39;alwaysSpan, overall dir (RTL) doesnt match &#39; +
<a name="line204"></a>      &#39;context dir (LTR), no dirReset&#39;,
<a name="line205"></a>      &#39;&lt;span dir=&quot;rtl&quot;&gt;&#39; + he + &#39;&lt;\/span&gt;&#39;,
<a name="line206"></a>      ltrAlwaysSpanFmt.spanWrap(he, true, false));
<a name="line207"></a>  assertEquals(&#39;alwaysSpan, overall dir (RTL) doesnt match &#39; +
<a name="line208"></a>      &#39;context dir (LTR), dirReset&#39;,
<a name="line209"></a>      &#39;&lt;span dir=&quot;rtl&quot;&gt;&#39; + he + &#39;&lt;\/span&gt;&#39; + LRM,
<a name="line210"></a>      ltrAlwaysSpanFmt.spanWrap(he, true, true));
<a name="line211"></a>  assertEquals(&#39;alwaysSpan, overall dir (neutral) doesnt match &#39; +
<a name="line212"></a>      &#39;context dir (LTR), dirReset&#39;,
<a name="line213"></a>      &#39;&lt;span&gt;&lt;/span&gt;&#39;,
<a name="line214"></a>      ltrAlwaysSpanFmt.spanWrap(&#39;&#39;, true, true));
<a name="line215"></a>}
<a name="line216"></a>
<a name="line217"></a>function testSpanWrapWithKnownDir() {
<a name="line218"></a>  assertEquals(&#39;known LTR in LTR context&#39;,
<a name="line219"></a>      en, ltrFmt.spanWrapWithKnownDir(LTR, en));
<a name="line220"></a>  assertEquals(&#39;unknown LTR in LTR context&#39;,
<a name="line221"></a>      en, ltrFmt.spanWrapWithKnownDir(null, en));
<a name="line222"></a>  assertEquals(&#39;overall LTR but exit RTL in LTR context&#39;,
<a name="line223"></a>      he + LRM, ltrFmt.spanWrapWithKnownDir(LTR, he));
<a name="line224"></a>  assertEquals(&#39;known RTL in LTR context&#39;,
<a name="line225"></a>      &#39;&lt;span dir=&quot;rtl&quot;&gt;&#39; + he + &#39;&lt;\/span&gt;&#39; + LRM,
<a name="line226"></a>      ltrFmt.spanWrapWithKnownDir(RTL, he));
<a name="line227"></a>  assertEquals(&#39;unknown RTL in LTR context&#39;,
<a name="line228"></a>      &#39;&lt;span dir=&quot;rtl&quot;&gt;&#39; + he + &#39;&lt;\/span&gt;&#39; + LRM,
<a name="line229"></a>      ltrFmt.spanWrapWithKnownDir(null, he));
<a name="line230"></a>  assertEquals(&#39;overall RTL but exit LTR in LTR context&#39;,
<a name="line231"></a>      &#39;&lt;span dir=&quot;rtl&quot;&gt;&#39; + en + &#39;&lt;\/span&gt;&#39; + LRM,
<a name="line232"></a>      ltrFmt.spanWrapWithKnownDir(RTL, en));
<a name="line233"></a>  assertEquals(&#39;known neutral in LTR context&#39;,
<a name="line234"></a>      &#39;.&#39;, ltrFmt.spanWrapWithKnownDir(NEUTRAL, &#39;.&#39;));
<a name="line235"></a>  assertEquals(&#39;unknown neutral in LTR context&#39;,
<a name="line236"></a>      &#39;.&#39;, ltrFmt.spanWrapWithKnownDir(null, &#39;.&#39;));
<a name="line237"></a>  assertEquals(&#39;overall neutral but exit LTR in LTR context&#39;,
<a name="line238"></a>      en, ltrFmt.spanWrapWithKnownDir(NEUTRAL, en));
<a name="line239"></a>  assertEquals(&#39;overall neutral but exit RTL in LTR context&#39;,
<a name="line240"></a>      he + LRM, ltrFmt.spanWrapWithKnownDir(NEUTRAL, he));
<a name="line241"></a>
<a name="line242"></a>  assertEquals(&#39;known RTL in RTL context&#39;,
<a name="line243"></a>      he, rtlFmt.spanWrapWithKnownDir(RTL, he));
<a name="line244"></a>  assertEquals(&#39;unknown RTL in RTL context&#39;,
<a name="line245"></a>      he, rtlFmt.spanWrapWithKnownDir(null, he));
<a name="line246"></a>  assertEquals(&#39;overall RTL but exit LTR in RTL context&#39;,
<a name="line247"></a>      en + RLM, rtlFmt.spanWrapWithKnownDir(RTL, en));
<a name="line248"></a>  assertEquals(&#39;known LTR in RTL context&#39;,
<a name="line249"></a>      &#39;&lt;span dir=&quot;ltr&quot;&gt;&#39; + en + &#39;&lt;\/span&gt;&#39; + RLM,
<a name="line250"></a>      rtlFmt.spanWrapWithKnownDir(LTR, en));
<a name="line251"></a>  assertEquals(&#39;unknown LTR in RTL context&#39;,
<a name="line252"></a>      &#39;&lt;span dir=&quot;ltr&quot;&gt;&#39; + en + &#39;&lt;\/span&gt;&#39; + RLM,
<a name="line253"></a>      rtlFmt.spanWrapWithKnownDir(null, en));
<a name="line254"></a>  assertEquals(&#39;LTR but exit RTL in RTL context&#39;,
<a name="line255"></a>      &#39;&lt;span dir=&quot;ltr&quot;&gt;&#39; + he + &#39;&lt;\/span&gt;&#39; + RLM,
<a name="line256"></a>      rtlFmt.spanWrapWithKnownDir(LTR, he));
<a name="line257"></a>  assertEquals(&#39;known neutral in RTL context&#39;,
<a name="line258"></a>      &#39;.&#39;, rtlFmt.spanWrapWithKnownDir(NEUTRAL, &#39;.&#39;));
<a name="line259"></a>  assertEquals(&#39;unknown neutral in RTL context&#39;,
<a name="line260"></a>      &#39;.&#39;, rtlFmt.spanWrapWithKnownDir(null, &#39;.&#39;));
<a name="line261"></a>  assertEquals(&#39;overall neutral but exit LTR in LTR context&#39;,
<a name="line262"></a>      he, rtlFmt.spanWrapWithKnownDir(NEUTRAL, he));
<a name="line263"></a>  assertEquals(&#39;overall neutral but exit RTL in LTR context&#39;,
<a name="line264"></a>      en + RLM, rtlFmt.spanWrapWithKnownDir(NEUTRAL, en));
<a name="line265"></a>
<a name="line266"></a>  assertEquals(&#39;known RTL in unknown context&#39;,
<a name="line267"></a>      &#39;&lt;span dir=&quot;rtl&quot;&gt;&#39; + he + &#39;&lt;\/span&gt;&#39;,
<a name="line268"></a>      unkFmt.spanWrapWithKnownDir(RTL, he));
<a name="line269"></a>  assertEquals(&#39;unknown RTL in unknown context&#39;,
<a name="line270"></a>      &#39;&lt;span dir=&quot;rtl&quot;&gt;&#39; + he + &#39;&lt;\/span&gt;&#39;,
<a name="line271"></a>      unkFmt.spanWrapWithKnownDir(null, he));
<a name="line272"></a>  assertEquals(&#39;overall RTL but exit LTR in unknown context&#39;,
<a name="line273"></a>      &#39;&lt;span dir=&quot;rtl&quot;&gt;&#39; + en + &#39;&lt;\/span&gt;&#39;,
<a name="line274"></a>      unkFmt.spanWrapWithKnownDir(RTL, en));
<a name="line275"></a>  assertEquals(&#39;known LTR in unknown context&#39;,
<a name="line276"></a>      &#39;&lt;span dir=&quot;ltr&quot;&gt;&#39; + en + &#39;&lt;\/span&gt;&#39;,
<a name="line277"></a>      unkFmt.spanWrapWithKnownDir(LTR, en));
<a name="line278"></a>  assertEquals(&#39;unknown LTR in unknown context&#39;,
<a name="line279"></a>      &#39;&lt;span dir=&quot;ltr&quot;&gt;&#39; + en + &#39;&lt;\/span&gt;&#39;,
<a name="line280"></a>      unkFmt.spanWrapWithKnownDir(null, en));
<a name="line281"></a>  assertEquals(&#39;LTR but exit RTL in unknown context&#39;,
<a name="line282"></a>      &#39;&lt;span dir=&quot;ltr&quot;&gt;&#39; + he + &#39;&lt;\/span&gt;&#39;,
<a name="line283"></a>      unkFmt.spanWrapWithKnownDir(LTR, he));
<a name="line284"></a>  assertEquals(&#39;known neutral in unknown context&#39;,
<a name="line285"></a>      &#39;.&#39;, unkFmt.spanWrapWithKnownDir(NEUTRAL, &#39;.&#39;));
<a name="line286"></a>  assertEquals(&#39;unknown neutral in unknown context&#39;,
<a name="line287"></a>      &#39;.&#39;, unkFmt.spanWrapWithKnownDir(null, &#39;.&#39;));
<a name="line288"></a>  assertEquals(&#39;overall neutral but exit LTR in unknown context&#39;,
<a name="line289"></a>      he, unkFmt.spanWrapWithKnownDir(NEUTRAL, he));
<a name="line290"></a>  assertEquals(&#39;overall neutral but exit RTL in unknown context&#39;,
<a name="line291"></a>      en, unkFmt.spanWrapWithKnownDir(NEUTRAL, en));
<a name="line292"></a>}
<a name="line293"></a>
<a name="line294"></a>function testUnicodeWrap() {
<a name="line295"></a>  // opt_isHtml is true, unless specified otherwise.
<a name="line296"></a>  assertEquals(&#39;overall dir matches context dir (LTR), no dirReset&#39;,
<a name="line297"></a>      en, ltrFmt.unicodeWrap(en, true, false));
<a name="line298"></a>  assertEquals(&#39;overall dir matches context dir (LTR), dirReset&#39;,
<a name="line299"></a>      en, ltrFmt.unicodeWrap(en, true, true));
<a name="line300"></a>  assertEquals(&#39;overall dir matches context dir (RTL), no dirReset&#39;,
<a name="line301"></a>      he, rtlFmt.unicodeWrap(he, true, false));
<a name="line302"></a>  assertEquals(&#39;overall dir matches context dir (RTL), dirReset&#39;,
<a name="line303"></a>      he, rtlFmt.unicodeWrap(he, true, true));
<a name="line304"></a>
<a name="line305"></a>  assertEquals(&#39;overall dir (RTL) doesnt match context dir (LTR), &#39; +
<a name="line306"></a>      &#39;no dirReset&#39;,
<a name="line307"></a>      RLE + he + PDF, ltrFmt.unicodeWrap(he, true, false));
<a name="line308"></a>  assertEquals(&#39;overall dir (RTL) doesnt match context dir (LTR), dirReset&#39;,
<a name="line309"></a>      RLE + he + PDF + LRM, ltrFmt.unicodeWrap(he, true, true));
<a name="line310"></a>  assertEquals(&#39;overall dir (LTR) doesnt match context dir (RTL), &#39; +
<a name="line311"></a>      &#39;no dirReset&#39;,
<a name="line312"></a>      LRE + en + PDF, rtlFmt.unicodeWrap(en, true, false));
<a name="line313"></a>  assertEquals(&#39;overall dir (LTR) doesnt match context dir (RTL), dirReset&#39;,
<a name="line314"></a>      LRE + en + PDF + RLM, rtlFmt.unicodeWrap(en, true, true));
<a name="line315"></a>  assertEquals(&#39;overall dir (LTR) doesnt match context dir (unknown), &#39; +
<a name="line316"></a>      &#39;no dirReset&#39;,
<a name="line317"></a>      LRE + en + PDF, unkFmt.unicodeWrap(en, true, false));
<a name="line318"></a>  assertEquals(&#39;overall dir (RTL) doesnt match context dir (unknown), &#39; +
<a name="line319"></a>      &#39;dirReset&#39;,
<a name="line320"></a>      RLE + he + PDF, unkFmt.unicodeWrap(he, true, true));
<a name="line321"></a>  assertEquals(&#39;overall dir (neutral) doesnt match context dir (LTR), &#39; +
<a name="line322"></a>      &#39;dirReset&#39;,
<a name="line323"></a>      &#39;&#39;,
<a name="line324"></a>      ltrFmt.unicodeWrap(&#39;&#39;, true, true));
<a name="line325"></a>
<a name="line326"></a>  assertEquals(&#39;exit dir (but not overall dir) is opposite to context dir, &#39; +
<a name="line327"></a>      &#39;dirReset&#39;,
<a name="line328"></a>      longEn + he + html + LRM,
<a name="line329"></a>      ltrFmt.unicodeWrap(longEn + he + html, true, true));
<a name="line330"></a>  assertEquals(&#39;overall dir (but not exit dir) is opposite to context dir, &#39; +
<a name="line331"></a>      &#39;dirReset&#39;,
<a name="line332"></a>      LRE + longEn + he + PDF + RLM,
<a name="line333"></a>      rtlFmt.unicodeWrap(longEn + he, true, true));
<a name="line334"></a>}
<a name="line335"></a>
<a name="line336"></a>function testUnicodeWrapWithKnownDir() {
<a name="line337"></a>  assertEquals(&#39;known LTR in LTR context&#39;,
<a name="line338"></a>      en, ltrFmt.unicodeWrapWithKnownDir(LTR, en));
<a name="line339"></a>  assertEquals(&#39;unknown LTR in LTR context&#39;,
<a name="line340"></a>      en, ltrFmt.unicodeWrapWithKnownDir(null, en));
<a name="line341"></a>  assertEquals(&#39;overall LTR but exit RTL in LTR context&#39;,
<a name="line342"></a>      he + LRM, ltrFmt.unicodeWrapWithKnownDir(LTR, he));
<a name="line343"></a>  assertEquals(&#39;known RTL in LTR context&#39;,
<a name="line344"></a>      RLE + he + PDF + LRM,
<a name="line345"></a>      ltrFmt.unicodeWrapWithKnownDir(RTL, he));
<a name="line346"></a>  assertEquals(&#39;unknown RTL in LTR context&#39;,
<a name="line347"></a>      RLE + he + PDF + LRM,
<a name="line348"></a>      ltrFmt.unicodeWrapWithKnownDir(null, he));
<a name="line349"></a>  assertEquals(&#39;overall RTL but exit LTR in LTR context&#39;,
<a name="line350"></a>      RLE + en + PDF + LRM,
<a name="line351"></a>      ltrFmt.unicodeWrapWithKnownDir(RTL, en));
<a name="line352"></a>  assertEquals(&#39;known neutral in LTR context&#39;,
<a name="line353"></a>      &#39;.&#39;, ltrFmt.unicodeWrapWithKnownDir(NEUTRAL, &#39;.&#39;));
<a name="line354"></a>  assertEquals(&#39;unknown neutral in LTR context&#39;,
<a name="line355"></a>      &#39;.&#39;, ltrFmt.unicodeWrapWithKnownDir(null, &#39;.&#39;));
<a name="line356"></a>  assertEquals(&#39;overall neutral but exit LTR in LTR context&#39;,
<a name="line357"></a>      en, ltrFmt.unicodeWrapWithKnownDir(NEUTRAL, en));
<a name="line358"></a>  assertEquals(&#39;overall neutral but exit RTL in LTR context&#39;,
<a name="line359"></a>      he + LRM,
<a name="line360"></a>      ltrFmt.unicodeWrapWithKnownDir(NEUTRAL, he));
<a name="line361"></a>
<a name="line362"></a>  assertEquals(&#39;known RTL in RTL context&#39;,
<a name="line363"></a>      he, rtlFmt.unicodeWrapWithKnownDir(RTL, he));
<a name="line364"></a>  assertEquals(&#39;unknown RTL in RTL context&#39;,
<a name="line365"></a>      he, rtlFmt.unicodeWrapWithKnownDir(null, he));
<a name="line366"></a>  assertEquals(&#39;overall RTL but exit LTR in RTL context&#39;,
<a name="line367"></a>      en + RLM, rtlFmt.unicodeWrapWithKnownDir(RTL, en));
<a name="line368"></a>  assertEquals(&#39;known LTR in RTL context&#39;,
<a name="line369"></a>      LRE + en + PDF + RLM,
<a name="line370"></a>      rtlFmt.unicodeWrapWithKnownDir(LTR, en));
<a name="line371"></a>  assertEquals(&#39;unknown LTR in RTL context&#39;,
<a name="line372"></a>      LRE + en + PDF + RLM,
<a name="line373"></a>      rtlFmt.unicodeWrapWithKnownDir(null, en));
<a name="line374"></a>  assertEquals(&#39;LTR but exit RTL in RTL context&#39;,
<a name="line375"></a>      LRE + he + PDF + RLM,
<a name="line376"></a>      rtlFmt.unicodeWrapWithKnownDir(LTR, he));
<a name="line377"></a>  assertEquals(&#39;known neutral in RTL context&#39;,
<a name="line378"></a>      &#39;.&#39;, rtlFmt.unicodeWrapWithKnownDir(NEUTRAL, &#39;.&#39;));
<a name="line379"></a>  assertEquals(&#39;unknown neutral in RTL context&#39;,
<a name="line380"></a>      &#39;.&#39;, rtlFmt.unicodeWrapWithKnownDir(null, &#39;.&#39;));
<a name="line381"></a>  assertEquals(&#39;overall neutral but exit LTR in LTR context&#39;,
<a name="line382"></a>      he, rtlFmt.unicodeWrapWithKnownDir(NEUTRAL, he));
<a name="line383"></a>  assertEquals(&#39;overall neutral but exit RTL in LTR context&#39;,
<a name="line384"></a>      en + RLM,
<a name="line385"></a>      rtlFmt.unicodeWrapWithKnownDir(NEUTRAL, en));
<a name="line386"></a>
<a name="line387"></a>  assertEquals(&#39;known RTL in unknown context&#39;,
<a name="line388"></a>      RLE + he + PDF,
<a name="line389"></a>      unkFmt.unicodeWrapWithKnownDir(RTL, he));
<a name="line390"></a>  assertEquals(&#39;unknown RTL in unknown context&#39;,
<a name="line391"></a>      RLE + he + PDF,
<a name="line392"></a>      unkFmt.unicodeWrapWithKnownDir(null, he));
<a name="line393"></a>  assertEquals(&#39;overall RTL but exit LTR in unknown context&#39;,
<a name="line394"></a>      RLE + en + PDF,
<a name="line395"></a>      unkFmt.unicodeWrapWithKnownDir(RTL, en));
<a name="line396"></a>  assertEquals(&#39;known LTR in unknown context&#39;,
<a name="line397"></a>      LRE + en + PDF,
<a name="line398"></a>      unkFmt.unicodeWrapWithKnownDir(LTR, en));
<a name="line399"></a>  assertEquals(&#39;unknown LTR in unknown context&#39;,
<a name="line400"></a>      LRE + en + PDF,
<a name="line401"></a>      unkFmt.unicodeWrapWithKnownDir(null, en));
<a name="line402"></a>  assertEquals(&#39;LTR but exit RTL in unknown context&#39;,
<a name="line403"></a>      LRE + he + PDF,
<a name="line404"></a>      unkFmt.unicodeWrapWithKnownDir(LTR, he));
<a name="line405"></a>  assertEquals(&#39;known neutral in unknown context&#39;,
<a name="line406"></a>      &#39;.&#39;, unkFmt.unicodeWrapWithKnownDir(NEUTRAL, &#39;.&#39;));
<a name="line407"></a>  assertEquals(&#39;unknown neutral in unknown context&#39;,
<a name="line408"></a>      &#39;.&#39;, unkFmt.unicodeWrapWithKnownDir(null, &#39;.&#39;));
<a name="line409"></a>  assertEquals(&#39;overall neutral but exit LTR in unknown context&#39;,
<a name="line410"></a>      he, unkFmt.unicodeWrapWithKnownDir(NEUTRAL, he));
<a name="line411"></a>  assertEquals(&#39;overall neutral but exit RTL in unknown context&#39;,
<a name="line412"></a>      en, unkFmt.unicodeWrapWithKnownDir(NEUTRAL, en));
<a name="line413"></a>}
<a name="line414"></a>
<a name="line415"></a>function testMarkAfter() {
<a name="line416"></a>  assertEquals(&#39;exit dir (RTL) is opposite to context dir (LTR)&#39;,
<a name="line417"></a>      LRM, ltrFmt.markAfter(longEn + he + html, true));
<a name="line418"></a>  assertEquals(&#39;exit dir (LTR) is opposite to context dir (RTL)&#39;,
<a name="line419"></a>      RLM, rtlFmt.markAfter(longHe + en, true));
<a name="line420"></a>  assertEquals(&#39;exit dir (LTR) doesnt match context dir (unknown)&#39;,
<a name="line421"></a>      &#39;&#39;, unkFmt.markAfter(longEn + en, true));
<a name="line422"></a>  assertEquals(&#39;overall dir (RTL) is opposite to context dir (LTR)&#39;,
<a name="line423"></a>      LRM, ltrFmt.markAfter(longHe + en, true));
<a name="line424"></a>  assertEquals(&#39;overall dir (LTR) is opposite to context dir (RTL)&#39;,
<a name="line425"></a>      RLM, rtlFmt.markAfter(longEn + he, true));
<a name="line426"></a>  assertEquals(&#39;exit dir and overall dir match context dir (LTR)&#39;,
<a name="line427"></a>      &#39;&#39;, ltrFmt.markAfter(longEn + he + html, false));
<a name="line428"></a>  assertEquals(&#39;exit dir and overall dir matches context dir (RTL)&#39;,
<a name="line429"></a>      &#39;&#39;, rtlFmt.markAfter(longHe + he, true));
<a name="line430"></a>}
<a name="line431"></a>
<a name="line432"></a>function testMarkAfterKnownDir() {
<a name="line433"></a>  assertEquals(&#39;known LTR in LTR context&#39;,
<a name="line434"></a>      &#39;&#39;, ltrFmt.markAfterKnownDir(LTR, en));
<a name="line435"></a>  assertEquals(&#39;unknown LTR in LTR context&#39;,
<a name="line436"></a>      &#39;&#39;, ltrFmt.markAfterKnownDir(null, en));
<a name="line437"></a>  assertEquals(&#39;overall LTR but exit RTL in LTR context&#39;,
<a name="line438"></a>      LRM, ltrFmt.markAfterKnownDir(LTR, he));
<a name="line439"></a>  assertEquals(&#39;known RTL in LTR context&#39;,
<a name="line440"></a>      LRM, ltrFmt.markAfterKnownDir(RTL, he));
<a name="line441"></a>  assertEquals(&#39;unknown RTL in LTR context&#39;,
<a name="line442"></a>      LRM, ltrFmt.markAfterKnownDir(null, he));
<a name="line443"></a>  assertEquals(&#39;overall RTL but exit LTR in LTR context&#39;,
<a name="line444"></a>      LRM, ltrFmt.markAfterKnownDir(RTL, en));
<a name="line445"></a>  assertEquals(&#39;known neutral in LTR context&#39;,
<a name="line446"></a>      &#39;&#39;, ltrFmt.markAfterKnownDir(NEUTRAL, &#39;.&#39;));
<a name="line447"></a>  assertEquals(&#39;unknown neutral in LTR context&#39;,
<a name="line448"></a>      &#39;&#39;, ltrFmt.markAfterKnownDir(null, &#39;.&#39;));
<a name="line449"></a>  assertEquals(&#39;overall neutral but exit LTR in LTR context&#39;,
<a name="line450"></a>      &#39;&#39;, ltrFmt.markAfterKnownDir(NEUTRAL, en));
<a name="line451"></a>  assertEquals(&#39;overall neutral but exit RTL in LTR context&#39;,
<a name="line452"></a>      LRM, ltrFmt.markAfterKnownDir(NEUTRAL, he));
<a name="line453"></a>
<a name="line454"></a>  assertEquals(&#39;known RTL in RTL context&#39;,
<a name="line455"></a>      &#39;&#39;, rtlFmt.markAfterKnownDir(RTL, he));
<a name="line456"></a>  assertEquals(&#39;unknown RTL in RTL context&#39;,
<a name="line457"></a>      &#39;&#39;, rtlFmt.markAfterKnownDir(null, he));
<a name="line458"></a>  assertEquals(&#39;overall RTL but exit LTR in RTL context&#39;,
<a name="line459"></a>      RLM, rtlFmt.markAfterKnownDir(RTL, en));
<a name="line460"></a>  assertEquals(&#39;known LTR in RTL context&#39;,
<a name="line461"></a>      RLM, rtlFmt.markAfterKnownDir(LTR, en));
<a name="line462"></a>  assertEquals(&#39;unknown LTR in RTL context&#39;,
<a name="line463"></a>      RLM, rtlFmt.markAfterKnownDir(null, en));
<a name="line464"></a>  assertEquals(&#39;LTR but exit RTL in RTL context&#39;,
<a name="line465"></a>      RLM, rtlFmt.markAfterKnownDir(LTR, he));
<a name="line466"></a>  assertEquals(&#39;known neutral in RTL context&#39;,
<a name="line467"></a>      &#39;&#39;, rtlFmt.markAfterKnownDir(NEUTRAL, &#39;.&#39;));
<a name="line468"></a>  assertEquals(&#39;unknown neutral in RTL context&#39;,
<a name="line469"></a>      &#39;&#39;, rtlFmt.markAfterKnownDir(null, &#39;.&#39;));
<a name="line470"></a>  assertEquals(&#39;overall neutral but exit LTR in LTR context&#39;,
<a name="line471"></a>      &#39;&#39;, rtlFmt.markAfterKnownDir(NEUTRAL, he));
<a name="line472"></a>  assertEquals(&#39;overall neutral but exit RTL in LTR context&#39;,
<a name="line473"></a>      RLM, rtlFmt.markAfterKnownDir(NEUTRAL, en));
<a name="line474"></a>
<a name="line475"></a>  assertEquals(&#39;known RTL in unknown context&#39;,
<a name="line476"></a>      &#39;&#39;, unkFmt.markAfterKnownDir(RTL, he));
<a name="line477"></a>  assertEquals(&#39;unknown RTL in unknown context&#39;,
<a name="line478"></a>      &#39;&#39;, unkFmt.markAfterKnownDir(null, he));
<a name="line479"></a>  assertEquals(&#39;overall RTL but exit LTR in unknown context&#39;,
<a name="line480"></a>      &#39;&#39;, unkFmt.markAfterKnownDir(RTL, en));
<a name="line481"></a>  assertEquals(&#39;known LTR in unknown context&#39;,
<a name="line482"></a>      &#39;&#39;, unkFmt.markAfterKnownDir(LTR, en));
<a name="line483"></a>  assertEquals(&#39;unknown LTR in unknown context&#39;,
<a name="line484"></a>      &#39;&#39;, unkFmt.markAfterKnownDir(null, en));
<a name="line485"></a>  assertEquals(&#39;LTR but exit RTL in unknown context&#39;,
<a name="line486"></a>      &#39;&#39;, unkFmt.markAfterKnownDir(LTR, he));
<a name="line487"></a>  assertEquals(&#39;known neutral in unknown context&#39;,
<a name="line488"></a>      &#39;&#39;, unkFmt.markAfterKnownDir(NEUTRAL, &#39;.&#39;));
<a name="line489"></a>  assertEquals(&#39;unknown neutral in unknown context&#39;,
<a name="line490"></a>      &#39;&#39;, unkFmt.markAfterKnownDir(null, &#39;.&#39;));
<a name="line491"></a>  assertEquals(&#39;overall neutral but exit LTR in unknown context&#39;,
<a name="line492"></a>      &#39;&#39;, unkFmt.markAfterKnownDir(NEUTRAL, he));
<a name="line493"></a>  assertEquals(&#39;overall neutral but exit RTL in unknown context&#39;,
<a name="line494"></a>      &#39;&#39;, unkFmt.markAfterKnownDir(NEUTRAL, en));
<a name="line495"></a>}
<a name="line496"></a>
<a name="line497"></a>function testMark() {
<a name="line498"></a>  // Implicitly, also tests the constructor.
<a name="line499"></a>  assertEquals(LRM, (new goog.i18n.BidiFormatter(LTR)).mark());
<a name="line500"></a>  assertEquals(&#39;&#39;, (new goog.i18n.BidiFormatter(null)).mark());
<a name="line501"></a>  assertEquals(&#39;&#39;, (new goog.i18n.BidiFormatter(NEUTRAL)).mark());
<a name="line502"></a>  assertEquals(RLM, (new goog.i18n.BidiFormatter(RTL)).mark());
<a name="line503"></a>  assertEquals(RLM, (new goog.i18n.BidiFormatter(true)).mark());
<a name="line504"></a>  assertEquals(LRM, (new goog.i18n.BidiFormatter(false)).mark());
<a name="line505"></a>}
<a name="line506"></a>
<a name="line507"></a>function testStartEdge() {
<a name="line508"></a>  assertEquals(&#39;left&#39;, ltrFmt.startEdge());
<a name="line509"></a>  assertEquals(&#39;left&#39;, unkFmt.startEdge());
<a name="line510"></a>  assertEquals(&#39;right&#39;, rtlFmt.startEdge());
<a name="line511"></a>}
<a name="line512"></a>
<a name="line513"></a>function testEndEdge() {
<a name="line514"></a>  assertEquals(&#39;right&#39;, ltrFmt.endEdge());
<a name="line515"></a>  assertEquals(&#39;right&#39;, unkFmt.endEdge());
<a name="line516"></a>  assertEquals(&#39;left&#39;, rtlFmt.endEdge());
<a name="line517"></a>}
</pre>


</body>
</html>
